<?php
namespace app\admin\controller;
use app\admin\controller\AdminController;
/**
 * 帖子设置
 */
class ThreadController extends AdminController {
    /**
     * 当前模块参数
     */
    protected function _infoModule(){
        return array(
            'menu' => array(
                    array(
                        'name' => '帖子列表',
                        'url' => url('index'),
                        'icon' => 'bars',
                    ),
                ),
            );
    }

	/**
     * 列表
     */
    public function index(){
        //筛选条件
        $where = array();
        $keyword = request('request.keyword','');
        if(!empty($keyword)){
            $where[] = "A.title like \"%{$keyword}%\" OR A.thread_id = :keyword OR C.username = :keyword";
            $where[':keyword'] = $keyword;
        }
    	//设置目录导航
    	$this->adminCrumb[] = array('url'=>url('index'),'name'=>'帖子管理');
        //URL参数
        $pageMaps = array();
        $pageMaps['keyword'] = $keyword;
        $pageList = target('forum/Thread')->page(20)->loadList($where,20);
        $this->pager = target('forum/Thread')->pager;
        $page = $this->getPageShow($pageMaps);
        $this->assign('pageList', $pageList);
        $this->assign('page', $page);
        $this->assign('pageMaps',$pageMaps);
        $this->adminDisplay();
    }

    /**
     * 删除
     */
    public function del(){
        $threadId = request('post.data');
        if(empty($threadId)){
            $this->error('参数不能为空！');
        }
        //删除帖子操作
        if(target('forum/Thread')->delData($threadId)){
            $this->success('帖子删除成功！');
        }else{
            $msg = target('forum/Thread')->getError();
            if(empty($msg)){
                $this->error('帖子删除失败！');
            }else{
                $this->error($msg);
            }
        }
    }
}

